﻿Public Class Form1
  Private Sub Button1_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles Button1.Click

    OpenFileDialog1.InitialDirectory = _
       Me.TextBox2.Text
    OpenFileDialog1.Filter =
       "file di testo (*.txt)|*.txt|" &
       "tutti i file (*.*)|*.*"
    OpenFileDialog1.FilterIndex = 1
    OpenFileDialog1.RestoreDirectory = True

    If OpenFileDialog1.ShowDialog() =
        Windows.Forms.DialogResult.OK Then
      ' codice per leggere il file
      Me.TextBox1.Text =
        My.Computer.FileSystem.ReadAllText("" &
        OpenFileDialog1.FileName)
    End If
  End Sub

  Private Sub Button2_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles Button2.Click
    Me.TextBox1.Text = ""
  End Sub

  Private Sub Button3_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles Button3.Click
    SaveFileDialog1.InitialDirectory = _
       Me.TextBox2.Text
    SaveFileDialog1.Filter =
       "file di testo (*.txt)|*.txt|" &
       "tutti i file (*.*)|*.*"
    SaveFileDialog1.FilterIndex = 2
    SaveFileDialog1.RestoreDirectory = True

    If SaveFileDialog1.ShowDialog() =
        Windows.Forms.DialogResult.OK Then
      My.Computer.FileSystem.WriteAllText("" &
      SaveFileDialog1.FileName,
      Me.TextBox1.Text, False)
    End If
  End Sub

  Private Sub Button4_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles Button4.Click
    FolderBrowserDialog1.SelectedPath =
       Me.TextBox2.Text
    If FolderBrowserDialog1.ShowDialog() =
          Windows.Forms.DialogResult.OK Then
      Me.TextBox2.Text =
         FolderBrowserDialog1.SelectedPath
    End If
  End Sub

End Class
